<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function checkType(target){
	return Object.prototype.toString.call(target).slice(8, -1);
}

function deepClone(target){
	let result;
	if(checkType(target) === 'Object'){
		result = {};
		for(let key in target){
			result[key] = deepClone(target[key]);
		}
	}else if(checkType(target) === 'Array'){
		result = [];
		for(let i = 0; i < target.length; i ++){
			result[i] = deepClone(target[i]);
		}
	}else if(checkType(target) === 'Function'){
		result = new Function('return ' + target.toString()).call(this);
	}else if(checkType(target) === 'Date'){
		result = new Date(target.valueOf());
	}else if(checkType(target) === 'RegExp'){
		result = new RegExp(target);
	}else if(checkType(target) === 'Map'){
		result = new Map();
		target.forEach((v, k) => {
			result.set(k, deepClone(v));
		})
	}else if(checkType(target) === 'Set'){
		result = new Set();
		for(let val of target.values()){
			result.add(deepClone(val));
		}
	}else{
		result = target;
	}
	return result;
}

// 测试
var a = {
  name: '张三',
  skills: ['踢球', '跑步', '打羽毛球'],
  age: 18,
  love: {
    name: '小红',
    age: 16
  },
  map: new Map([['aaa', '123']]),
  fn:function(a){
    console.log(`我的名字叫${this.name}` + a)
  },
  set: new Set([1,2,3,4,5])
};

var newA = deepClone(a)
a.age = 100
a.love.age = 100
a.set.add('1123')
a.skills.push('计算机')
a.name = '小梅'
a.map.set('name', '小明')

console.log(a)
console.log(newA)

a.fn('a')
newA.fn('newA')

</script>

</body>
</html>